﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcAtletIS.Models
{
    [MetadataType(typeof(CompetitionsMetaData))]
    public partial class Competitions
    {
        public string sDateFrom
        {
            get
            {
                return this.DateFrom.Value.ToString("dd.MM.yyyy");
            }
        }
        
        public string sPropositions
        {
            get
            {
                return "http://www.atletikasvk.sk/Content/results/" +
                    this.DateFrom.Value.Year.ToString() + "/" +
                    this.DateFrom.Value.Month.ToString() + "/" +
                    "PROP" + this.ID.ToString() + ".pdf";
            }
        }
        
        public bool bPropositions
        {
            get 
            {
                string path = System.IO.Path.Combine("~/Content/results/",
                    this.DateFrom.Value.Year.ToString(),
                    this.DateFrom.Value.Month.ToString(),
                    "PROP" + this.ID.ToString() + ".pdf");

                path = System.Web.HttpContext.Current.Server.MapPath(path);

                if (System.IO.File.Exists(path))
                    return true;
                else
                    return false;
            }
        }

        public string sResults
        {
            get
            {
                return "http://www.atletikasvk.sk/Content/results/" +
                    this.DateFrom.Value.Year.ToString() + "/" +
                    this.DateFrom.Value.Month.ToString() + "/" +
                    "VYS" + this.ID.ToString() + ".pdf";
            }
        }
        
        public bool bResults
        {
            get
            {
                string path = System.IO.Path.Combine("~/Content/results/",
                    this.DateFrom.Value.Year.ToString(),
                    this.DateFrom.Value.Month.ToString(),
                    "VYS" + this.ID.ToString() + ".pdf");
                path = System.Web.HttpContext.Current.Server.MapPath(path);
                
                if (System.IO.File.Exists(path))
                    return true;
                else
                    return false;
            }
        }
    }

    public class CompetitionsMetaData
    {
        [DisplayName("Názov")]
        [Required(ErrorMessage = "Názov je povinný údaj.")]
        public string Name { get; set; }

        [DisplayName("Mesto")]
        public string City { get; set; }

        [DisplayName("Organizátor")]
        public string Organiser { get; set; }

        [DisplayName("Dátum od")]
        [Required(ErrorMessage = "Dátum od je povinný údaj.")]
        [DataType(DataType.Date)]
        public DateTime DateFrom { get; set; }

        [DisplayName("Dátum do")]
        [DataType(DataType.Date)]
        public DateTime DateTo { get; set; }

        [DisplayName("Ukončenie prihlášok")]
        [Required(ErrorMessage = "Ukončenie prihlášok je povinný údaj.")]
        [DataType(DataType.Date)]
        public DateTime Deadline { get; set; }

        [DisplayName("Kluby/krajiny")]
        [DefaultValue(true)]
        public bool ClubsCountries { get; set; }
        
        [DisplayName("Počet dráh")]
        [Required(ErrorMessage = "Počet dráh je povinný údaj.")]
        public int Lanes { get; set; }

        [DisplayName("Výhodnosť dráh")]
        [Required(ErrorMessage = "Výhodnosť dráh je povinný údaj.")]
        public string LanesQuality { get; set; }
        
        [DisplayName("Aktívna")]
        [DefaultValue(true)]
        public bool Active { get; set; }

        [DisplayName("Synch.")]
        [DefaultValue(true)]
        public bool Sync { get; set; }

        [DisplayName("Verejné")]
        [DefaultValue(false)]
        public bool Public { get; set; }

        [DisplayName("Externé")]
        [DefaultValue(false)]
        public bool External { get; set; }

        [DisplayName("Stránka podujatia")]
        public string Website { get; set; }

        [DisplayName("Prílohy pred")]
        public string PreAttachments { get; set; }

        [DisplayName("Prílohy po")]
        public string PostAttachments { get; set; }
    }
}